package chpt04;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable> {
	private String name;
	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public PersonSortable(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonSortable other = (PersonSortable) obj;
		if (age != other.age)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public int compareTo(PersonSortable o) {
		int x=this.name.compareTo(o.getName());
		if (x!=0)
			return x;
		else if (this.age < o.getAge())
			return -1;
		else if (this.age > o.getAge())
			return 1;
		else
			return 0;
	}

}

public class PortComparable {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while (in.hasNext()) {
			ArrayList<PersonSortable> persons = new ArrayList<PersonSortable>();
			for (int i = 0; i < n; i++) {
				persons.add(new PersonSortable(in.next(), in.nextInt()));
			}
			Collections.sort(persons);
			for (PersonSortable p : persons) {
				System.out.println(p);
			}
			System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		}
		in.close();
	}

}
